<!-- 实名认证  -->
<template>
  <view>
    <!-- 标题栏 -->
    <view class="head-box ss-m-b-60">
      <view class="head-title ss-m-b-20">实名认证</view>
      <view class="head-subtitle"
        >根据国家法律法规，该产品需要强行进行身份认证，请按照如下表单要求进行认证，我们不会透露任何个人信息</view
      >
    </view>

    <!-- 表单项 -->
    <uni-forms
      ref="editIdentifyRef"
      v-model="state.model"
      :rules="state.rules"
      validateTrigger="bind"
      labelWidth="140"
      labelAlign="center"
    >
      <uni-forms-item name="name" label="姓名">
        <uni-easyinput
          placeholder="请输入真实姓名"
          v-model="state.model.name"
          type="name"
          maxlength="4"
          :inputBorder="false"
        ></uni-easyinput>
      </uni-forms-item>

      <uni-forms-item name="idNumber" label="身份证号">
        <uni-easyinput
          type="password"
          placeholder="请输入身份证号"
          v-model="state.model.id_number"
          :inputBorder="false"
        >
        </uni-easyinput>
      </uni-forms-item>
    </uni-forms>

    <!-- 标题栏 -->
    <view class="head-box ss-m-b-60">
      <view class="head-title ss-m-b-20">推荐人信息</view>
      <view class="head-subtitle">根据产品要求，本产品需要您的推荐人信息，否则无法完成注册</view>
    </view>
    <uni-forms
      ref="editIdentifyRef"
      v-model="state.model"
      :rules="state.rules"
      validateTrigger="bind"
      labelWidth="140"
      labelAlign="center"
    >
      <!-- 表单项 -->
      <uni-forms-item name="recommendMobile" label="电话">
        <uni-easyinput
          type="recommendMobile"
          placeholder="请输入推荐人电话"
          v-model="state.model.recommend_mobile"
          :inputBorder="false"
        >
        </uni-easyinput>
      </uni-forms-item>
    </uni-forms>

    <button
      class="ss-reset-button login-btn-start type-btn"
      @tap="editIdentifySubmit"
      style="color: #fff"
    >
      点击注册
    </button>
    <button class="ss-reset-button type-btn" @tap="closeAuthModal"> 退出 </button>
  </view>
</template>

<script setup>
  import { ref, reactive, unref } from 'vue';
  import { code, password } from '@/sheep/validate/form';
  import { closeAuthModal, getSmsCode, getSmsTimer } from '@/sheep/hooks/useModal';
  import UserApi from '@/sheep/api/member/user';

  const editIdentifyRef = ref(null);

  // 数据
  const state = reactive({
    model: {
      mobile: '', // 手机号
      code: '9999', // 验证码
      password: '0000000000000000', // 密码
    },
    rules: {
      code,
      password,
    },
  });

  // 更改密码
  async function editIdentifySubmit() {
    // 参数校验
    const validate = await unref(editIdentifyRef)
      .validate()
      .catch((error) => {
        console.log('error: ', error);
      });
    if (!validate) {
      return;
    }
    // 发起请求
    const { code } = await UserApi.updateUserPassword(state.model);
    if (code !== 0) {
      return;
    }
    // 成功后，只需要关闭弹窗
    closeAuthModal();
  }
</script>

<style lang="scss" scoped>
  @import '../index.scss';
</style>
